// JavaScript Document

(function ($, undefined) {
	

	var getTipDayInfo = function (dayInfo) {
		
		// 添加一个图标列表
		var addIconsToDayInfo = function (dayInfoIcons) {
			var iconPanel = $('#lblDayInfo', tipDayInfoDom).children().first(); 
			$(dayInfoIcons).each ( function (index, item) {
			    var imgHtml = '<img src="../../content/icons/{iconName}" style="width: 48px; height: 48px;" title="{title}" />'
					.replace('{iconName}', item.iconName)			
					.replace('{title}', item.title);
				$(imgHtml).appendTo(iconPanel);
			});
		}
		
		// 添加其他文字说明信息
		var addOtherInfoToDayInfo = function () {
			var otherInfoPanel = $('#lblDayInfo', tipDayInfoDom).children().first().next();
			if (dayInfo.ExtraShiftInfo != null) {
				otherInfoPanel.html("今日 " + dayInfo.ExtraShiftInfo.Name + " 调休");
			}
		}
		
		var tipDayInfoTemplate = 		
			'<div id="tip_DayInfo" style="display: none;">' +
				'<h1>今天&nbsp;<div style="display: inline;" id="lblDate"></div></h1>' +
				'<div id="lblDayInfo" class="indent">' +
				'<p></p>' +
				'</div>' +
			'</div>	';
		var tipDayInfoDom = $(tipDayInfoTemplate);
		
		var dayInfoIcons = [];
		
		if (dayInfo.IsNeedToWork) {
			dayInfoIcons[dayInfoIcons.length] = { iconName : "work.png", title : "今天是工作日!" };
		} else {
			dayInfoIcons[dayInfoIcons.length] = { iconName : "rest.png", title : "今日休息" };			
		}
		
		if (dayInfo.IsWeekEnd) {
			dayInfoIcons[dayInfoIcons.length] = { iconName : "weekend.png", title : "周末！" };
		}
		
		if (dayInfo.HolidayInfo != null) {
			dayInfoIcons[dayInfoIcons.length] = { iconName : "holiday.png", title : dayInfo.HolidayInfo.Name};
		}
		
		addIconsToDayInfo(dayInfoIcons);
		
		addOtherInfoToDayInfo();
		
		
		// 加入当日时间
		var dateStr = Date.fromEpoch(dayInfo.Date).toFullChineseDateFormat();
		$('#lblDate', tipDayInfoDom).html(dateStr);

		return tipDayInfoDom;
	};
	
	$.tipDayInfo = function (dayInfo) {
		
		var _tipDayInfo = getTipDayInfo(dayInfo);
		
		EzTipsManager.addTipBox(_tipDayInfo, 'tipDayInfo');
		EzTipsManager.showTipBox('tipDayInfo');
	};

})(jQuery);